import Vue from 'vue'
import VueRouter from 'vue-router'
// import { component } from 'vue/types/umd'
import Home from '../views/Home.vue'
import Recommend from '../views/Recommend.vue'
import Note from '../views/Note.vue'
import Attention from '../views/Attention.vue'
import VideoList from '../views/VideoList.vue'
import Detail from '../views/Detail.vue'
import Search from '../views/Search.vue'
import Classify from '../views/Classify.vue'
import Login from '../views/Login.vue'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    component: Home,
    meta: {
      showNav: true,
      search: true,
    },
    children: [{
        path: "/",
        component: Recommend,
        meta: {
          showNav: true,
          search: true,
        },
      },
      {
        path: "attention",
        component: Attention,
        meta: {
          showNav: true,
          search: true,
        },
      },
      {
        path: "videolist",
        component: VideoList,
        meta: {
          showNav: true,
          search: true,
        },
      },
      {
        path: "note",
        component: Note,
        meta: {
          showNav: true,
          search: true,
        },
      }
    ]
  },
  {
    path: '/detail',
    component: Detail
  },
  {
    path: '/search',
    component: Search
  },
  {
    path: '/classify',
    component: Classify
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/course',
    name: 'Course',
    meta: {
      showNav: true,
      search: true,
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import( /* webpackChunkName: "about" */ '../views/Course.vue')
  },
  {
    path: '/market',
    name: 'Market',
    meta: {
      showNav: true,
      search: true,
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import( /* webpackChunkName: "about" */ '../views/Market.vue')
  },
  {
    path: '/like',
    name: 'Like',
    meta: {
      showNav: true,
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import( /* webpackChunkName: "about" */ '../views/Like.vue')
  },
  {
    path: '/my',
    name: 'My',
    meta: {
      showNav: true,
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import( /* webpackChunkName: "about" */ '../views/My.vue')
  },
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.fullPath == "/my" || to.fullPath == '/like') {
    if (localStorage.getItem('login') == "false") {
      next('/login?f=' + to.fullPath + '&b=' + from.fullPath);
    } else {
      next()
    }
  } else {
    next()
  }
})

export default router